<?php
namespace app\api\controller;

use app\home\model\Banner as ModelBanner;

class Banner
{
    public function index(){
        return json(ModelBanner::select());
    }
    public function add(){
        $data = request()->param();
        $banner = new ModelBanner ;
        $banner->save($data);
        return json(['banner'=>ModelBanner::find($banner->id)]);
    }
    public function edit(){
        $data = request()->param();
        $banner = ModelBanner::find($data['id']);
        $res = $banner->save([
            'img_url' => $data['img_url'],
            'redirect_url' => $data['redirect_url'],
            'order' => $data['order']
        ]);
        return json($res);
    }
    public function del(){
        $banner_id = request()->param('id');
        return ModelBanner::destroy($banner_id);
    }
}
